package com.xiaoyu.lingdian.controller;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import com.xiaoyu.lingdian.tool.FileUtil;
import com.xiaoyu.lingdian.tool.RandomUtil;
import com.xiaoyu.lingdian.tool.StringUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.xiaoyu.lingdian.core.mybatis.page.Page;

import org.springframework.stereotype.Controller;

import com.xiaoyu.lingdian.tool.init.ConfigIni;
import com.xiaoyu.lingdian.tool.out.ResultMessageBuilder;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import com.xiaoyu.lingdian.controller.BaseController;
import com.xiaoyu.lingdian.entity.CoreAttachment;
import com.xiaoyu.lingdian.entity.CoreTaobaoPic;
import com.xiaoyu.lingdian.service.CoreAttachmentService;
import com.xiaoyu.lingdian.service.CoreTaobaoPicService;
import com.xiaoyu.lingdian.vo.CoreTaobaoPicVO;

@Controller
@RequestMapping(value="/coreTaobaoPic")
public class CoreTaobaoPicController extends BaseController {

	private static final String DOT = ".";
	public static final String ZIP = "zip";
	public static final int DEFAULT_BUFFER_SIZE = 1024;
	
	/**
	* 淘宝表
	*/
	@Autowired
	private CoreTaobaoPicService coreTaobaoPicService;
	
	@Autowired
	private CoreAttachmentService coreAttachmentService;
	
	/**
	 * 不干胶上传附件（包括文件、图片）,支持多文件
	 * 
	 * @param account 淘宝账户名
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/upload", method = RequestMethod.POST)
	public void upload(String account, HttpServletRequest request, HttpServletResponse response) {
		logger.info("[CoreTaobaoPicController.upload]:begin upload.");
		if (StringUtil.isEmpty(account)) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "请填写淘宝号"),response);
			logger.info("[CoreTaobaoPicController]:end upload");
			return;
		}
		
		String uuids = "";
		String error = "";
		// 解析器解析request的上下文/创建一个通用的多部分解析器
		CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
				request.getSession().getServletContext());
		// 先判断request中是否包涵multipart类型的数据，
		if (multipartResolver.isMultipart(request)) {
			// 再将request中的数据转化成multipart类型的数据
			MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
			// 取得request中的所有文件名
			Iterator<String> iter = multiRequest.getFileNames();
			int i = 0;
			while (iter.hasNext()) {
				// 取得上传文件
				MultipartFile file = multiRequest.getFile(iter.next());
				if (file != null) {
					if (file.isEmpty()) {
						writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "文件为空，不能上传"), response);                   	
			    		logger.info("[CoreTaobaoPicController.upload]:end upload.");
			    		return;
					}
					i++;
					// 记录上传过程起始时的时间，用来计算上传时间
					int pre = (int) System.currentTimeMillis();
					String orignalFilename = file.getOriginalFilename(); //原文件名,带后缀
					String fileName = account + '-' + i + getAfterLastPoint(orignalFilename); //带随机数的新文件名	
					String uuid = RandomUtil.generateString(16);
					if (file.getSize() <= 31457280) { // 大小超过30M的不上传
						uuids += uuid;
						uuids += "|";
						String path = ConfigIni.getIniStrValue("ATTACHMENT_DIR", "path", "C:\\file\\") + "jgj/bgj/" + fileName;
						File localFile = new File(path);
						FileUtil.createFile(localFile);
						// 写文件到本地
						try {
							file.transferTo(localFile);
						} catch (IllegalStateException e) {
							logger.info(e.getMessage());
							error += orignalFilename;
							error += "上传失败：文件错误，不能上传到服务器";
							break;
						} catch (IOException e) {
							logger.info(e.getMessage());
							error += orignalFilename;
							error += "上传失败：文件错误，不能上传到服务器";
							break;
						}
						// 记录上传该文件后的时间
						int finaltime = (int) System.currentTimeMillis();
						int min = finaltime - pre;
						logger.info(fileName + "耗时 : " + min);
						// 插入数据库中
						CoreAttachment coreAttachment = new CoreAttachment();
						coreAttachment.setCratmUuid(uuid);
						coreAttachment.setCratmCdate(new Date());
						coreAttachment.setCratmFileName(fileName);
						coreAttachment.setCratmStatus(1);
						coreAttachment.setCratmDir("jgj/bgj");
						coreAttachment.setCratmExtension(getAfterLastPoint(fileName));
						coreAttachment.setCratmType(4);
						coreAttachmentService.insertCoreAttachment(coreAttachment);
					} else {
						error += orignalFilename;
						error += "上传失败：附件大小请保持在30M以内";
						break;
					}
				}				
			}
		}
		if (!("").equals(error)) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, error), response);                   	
    		logger.info("[CoreTaobaoPicController.upload]:end upload.");
    		return;
		}
		
		if (StringUtil.isEmpty(uuids)) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "文件必传"),response);
			logger.info("[CoreTaobaoPicController]:end upload");
			return;
		}

		CoreTaobaoPic coreTaobaoPic = new CoreTaobaoPic();
		String uuid = RandomUtil.generateString(16);
		coreTaobaoPic.setCrtpcUuid(uuid);
		coreTaobaoPic.setCrtpcAccount(account);
		coreTaobaoPic.setCrtpcFile(uuids);
		coreTaobaoPic.setCrtpcCdate(new Date());
		coreTaobaoPic.setCrtpcUdate(new Date());

		coreTaobaoPicService.insertCoreTaobaoPic(coreTaobaoPic);

		writeAjaxJSONResponse(ResultMessageBuilder.build(true, 1, "SUCCESS!"),response);
		logger.info("[CoreTaobaoPicController]:end upload");
	}
	
	/**
	 * 下载全部图片
	 * 
	 * @param fileDir
	 * @param response
	 */
	@RequestMapping(value = "/download/{fileDir}", method = RequestMethod.GET)
	public void download(@PathVariable("fileDir") String fileDir, HttpServletResponse response) {
		logger.info("[CoreTaobaoPicController]:begin download");
		try {
			String basePath = ConfigIni.getIniStrValue("ATTACHMENT_DIR", "path", "C:\\file\\") + "jgj/" + fileDir;
			File fullFolder = new File(basePath);
			if (fullFolder.exists()) {
				File[] reportFiles = fullFolder.listFiles();
				if (reportFiles != null && reportFiles.length > 0) {
					// 有文件需打包zip并输出
					String zipFileName = fileDir + DOT + ZIP;
					response.setContentType("application/zip");
					response.setHeader("Content-Disposition", "attachment; filename=\"" + zipFileName + "\"");
					ZipOutputStream output = null;
					byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];

					output = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream(),
							DEFAULT_BUFFER_SIZE));
					try {
						for (File file : reportFiles) {
							InputStream input = null;
							try (FileInputStream fis = new FileInputStream(file)) {
								input = new BufferedInputStream(fis, DEFAULT_BUFFER_SIZE);
								output.putNextEntry(new ZipEntry(file.getName()));
								int length = 0;
								while ((length = input.read(buffer)) > 0) {
									output.write(buffer, 0, length);
								}
							} finally {
								output.closeEntry();

								if (input != null) {
									input.close();
								}
							}
						}
					} finally {
						output.close();
					}
				} else {
					writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, basePath + "文件目录没文件"),response);
					logger.info("[CoreTaobaoPicController]:end download");
					return;
				}
			} else {
				writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, basePath + "文件目录不存在"),response);
				logger.info("[CoreTaobaoPicController]:end download");
				return;
			}
		} catch (Exception e) {
			logger.info("failed to download file", e);
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "下载文件失败"),response);
			logger.info("[CoreTaobaoPicController]:end download");
			return;
		}
	}
	
	/**
	 * 下载单个淘宝号图片
	 * 
	 * @param crtpcUuid
	 * @param response
	 */
	@RequestMapping(value = "/download/account/{crtpcUuid}", method = RequestMethod.GET)
	public void downloadByUuid(@PathVariable("crtpcUuid") String crtpcUuid, HttpServletResponse response) {
		logger.info("[CoreTaobaoPicController]:begin downloadByUuid");
		try {
			CoreTaobaoPic coreTaobaoPic = new CoreTaobaoPic();
			coreTaobaoPic.setCrtpcUuid(crtpcUuid);

			coreTaobaoPic = coreTaobaoPicService.getCoreTaobaoPic(coreTaobaoPic);

			if (coreTaobaoPic == null) {
				writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "文件错误"),response);
				logger.info("[CoreTaobaoPicController]:end downloadByUuid");
				return;
			}
			
			// 有文件需打包zip并输出
			String zipFileName = coreTaobaoPic.getCrtpcAccount() + DOT + ZIP;
			response.setContentType("application/zip");
			response.setHeader("Content-Disposition", "attachment; filename=\"" + zipFileName + "\"");
			ZipOutputStream output = null;
			byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];

			output = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream(),
					DEFAULT_BUFFER_SIZE));
			
			String[] attachments = coreTaobaoPic.getCrtpcFile().split("\\|");
			try {
				
				for (int i = 0; i < attachments.length; i++) {
					CoreAttachment coreAttachment = new CoreAttachment();
					coreAttachment.setCratmUuid(attachments[i]);
					coreAttachment = coreAttachmentService.getCoreAttachment(coreAttachment); // 获取
					if (coreAttachment == null) {
						continue;
					}
					String path = ConfigIni.getIniStrValue("ATTACHMENT_DIR", "path", "C:\\file\\") + coreAttachment.getCratmDir() + "/" + coreAttachment.getCratmFileName();
					File newFile = new File(path);
					InputStream input = null;
					try (FileInputStream fis = new FileInputStream(newFile)) {
						input = new BufferedInputStream(fis, DEFAULT_BUFFER_SIZE);
						output.putNextEntry(new ZipEntry(newFile.getName()));
						int length = 0;
						while ((length = input.read(buffer)) > 0) {
							output.write(buffer, 0, length);
						}
					} finally {
						output.closeEntry();
	
						if (input != null) {
							input.close();
						}
					}
				}
			} finally {
				output.close();
			}		
		} catch (Exception e) {
			logger.info("failed to download file", e);
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "下载文件失败"),response);
			logger.info("[CoreTaobaoPicController]:end downloadByUuid");
			return;
		}
	}
	
	/**
	* 添加
	*
	* @param crtpcAccount 淘宝号
	* @param crtpcFile 淘宝文件
	* @return
	*/
	@RequestMapping(value="/add/coreTaobaoPic", method=RequestMethod.POST)
	public void addCoreTaobaoPic (String crtpcAccount, String crtpcFile, HttpServletResponse response) {
		logger.info("[CoreTaobaoPicController]:begin addCoreTaobaoPic");

		if (StringUtil.isEmpty(crtpcAccount)) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "请填写淘宝号"),response);
			logger.info("[CoreTaobaoPicController]:end addCoreTaobaoPic");
			return;
		}
		if (StringUtil.isEmpty(crtpcFile)) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "文件必传"),response);
			logger.info("[CoreTaobaoPicController]:end addCoreTaobaoPic");
			return;
		}
		CoreTaobaoPic coreTaobaoPic = new CoreTaobaoPic();
		String uuid = RandomUtil.generateString(16);
		coreTaobaoPic.setCrtpcUuid(uuid);
		coreTaobaoPic.setCrtpcAccount(crtpcAccount);
		coreTaobaoPic.setCrtpcFile(crtpcFile);
		coreTaobaoPic.setCrtpcCdate(new Date());
		coreTaobaoPic.setCrtpcUdate(new Date());

		coreTaobaoPicService.insertCoreTaobaoPic(coreTaobaoPic);

		writeAjaxJSONResponse(ResultMessageBuilder.build(true, 1, "新增成功!"),response);
		logger.info("[CoreTaobaoPicController]:end addCoreTaobaoPic");

	}

	/**
	* 删除
	*
	* @param crtpcUuid 标识UUID
	* @return
	*/
	@RequestMapping(value="/delete/one", method=RequestMethod.POST)
	public void deleteCoreTaobaoPic (String crtpcUuid, HttpServletResponse response) {
		logger.info("[CoreTaobaoPicController]:begin deleteCoreTaobaoPic");
		if (StringUtil.isEmpty(crtpcUuid)) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "[标识UUID]不能为空!"), response);
			return;
		}
		CoreTaobaoPic coreTaobaoPic = new CoreTaobaoPic();
		coreTaobaoPic.setCrtpcUuid(crtpcUuid);
		//删除文件
		coreTaobaoPic = coreTaobaoPicService.getCoreTaobaoPic(coreTaobaoPic);

		if (coreTaobaoPic == null) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "淘宝文件不存在"),response);
			logger.info("[CoreTaobaoPicController]:end deleteCoreTaobaoPic");
			return;
		}
		
		String[] attachments = coreTaobaoPic.getCrtpcFile().split("\\|");
		for (int i = 0; i < attachments.length; i++) {
			CoreAttachment coreAttachment = new CoreAttachment();
			coreAttachment.setCratmUuid(attachments[i]);
			coreAttachment = coreAttachmentService
					.getCoreAttachment(coreAttachment); // 获取
			if (coreAttachment == null) {
				continue;
			}
			String path = ConfigIni.getIniStrValue("ATTACHMENT_DIR", "path",
					"C:\\file\\")
					+ coreAttachment.getCratmDir()
					+ "/"
					+ coreAttachment.getCratmFileName();

			FileUtil.deleteFile(path); // 删除缩略图
		}
		coreTaobaoPicService.deleteCoreTaobaoPic(coreTaobaoPic);

		writeAjaxJSONResponse(ResultMessageBuilder.build(true, 1, "删除成功!"),response);
		logger.info("[CoreTaobaoPicController]:end deleteCoreTaobaoPic");

	}

	/**
	 * 批量下载淘宝号图片
	 * 
	 * @param crtpcUuids
	 * @param response
	 */
	@RequestMapping(value = "/download/batch/account/{crtpcUuids}", method = RequestMethod.GET)
	public void downloadByUuids(@PathVariable("crtpcUuids") String crtpcUuids, HttpServletResponse response) {
		logger.info("[CoreTaobaoPicController]:begin downloadByUuids");
		try {
			if (StringUtil.isEmpty(crtpcUuids)) {
				writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "[UUID集合]不能为空!"), response);
				return;
			}

			String[] uuids=crtpcUuids.split("\\|");
			List<String> list = new ArrayList<String>();
			for (int i = 0; i < uuids.length; i++) {
				CoreTaobaoPic coreTaobaoPic = new CoreTaobaoPic();
				coreTaobaoPic.setCrtpcUuid(uuids[i]);
				coreTaobaoPic = coreTaobaoPicService.getCoreTaobaoPic(coreTaobaoPic);

				if (coreTaobaoPic != null) {
					String[] attachments = coreTaobaoPic.getCrtpcFile().split("\\|");
					for (int y = 0; y < attachments.length; y++) {
						list.add(attachments[y]);
					}
				}
			}
			
			// 有文件需打包zip并输出
			String zipFileName = "bgj_batch" + DOT + ZIP;
			response.setContentType("application/zip");
			response.setHeader("Content-Disposition", "attachment; filename=\"" + zipFileName + "\"");
			ZipOutputStream output = null;
			byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];

			output = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream(),
					DEFAULT_BUFFER_SIZE));

			try {				
				for (String strUuid : list) {
					CoreAttachment coreAttachment = new CoreAttachment();
					coreAttachment.setCratmUuid(strUuid);
					coreAttachment = coreAttachmentService.getCoreAttachment(coreAttachment); // 获取
					if (coreAttachment == null) {
						continue;
					}
					String path = ConfigIni.getIniStrValue("ATTACHMENT_DIR", "path", "C:\\file\\") + coreAttachment.getCratmDir() + "/" + coreAttachment.getCratmFileName();
					File newFile = new File(path);
					InputStream input = null;
					try (FileInputStream fis = new FileInputStream(newFile)) {
						input = new BufferedInputStream(fis, DEFAULT_BUFFER_SIZE);
						output.putNextEntry(new ZipEntry(newFile.getName()));
						int length = 0;
						while ((length = input.read(buffer)) > 0) {
							output.write(buffer, 0, length);
						}
					} finally {
						output.closeEntry();
	
						if (input != null) {
							input.close();
						}
					}
				}
			} finally {
				output.close();
			}		
		} catch (Exception e) {
			logger.info("failed to download file", e);
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "下载文件失败"),response);
			logger.info("[CoreTaobaoPicController]:end downloadByUuids");
			return;
		}
	}
	
	/**
	* 批量删除
	*
	* @param crtpcUuids UUID集合
	* @return
	*/
	@RequestMapping(value="/delete/batch", method=RequestMethod.POST)
	public void deleteBatchCoreTaobaoPic (String crtpcUuids, HttpServletResponse response) {
		logger.info("[CoreTaobaoPicController]:begin deleteBatchCoreTaobaoPic");
		if (StringUtil.isEmpty(crtpcUuids)) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "[UUID集合]不能为空!"), response);
			return;
		}
		String[] uuids=crtpcUuids.split("\\|");
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < uuids.length; i++) {
			CoreTaobaoPic coreTaobaoPic = new CoreTaobaoPic();
			coreTaobaoPic.setCrtpcUuid(uuids[i]);
			//删除文件
			coreTaobaoPic = coreTaobaoPicService.getCoreTaobaoPic(coreTaobaoPic);

			if (coreTaobaoPic != null) {
				String[] attachments = coreTaobaoPic.getCrtpcFile().split("\\|");
				for (int y = 0; y < attachments.length; y++) {
					CoreAttachment coreAttachment = new CoreAttachment();
					coreAttachment.setCratmUuid(attachments[y]);
					coreAttachment = coreAttachmentService
							.getCoreAttachment(coreAttachment); // 获取
					if (coreAttachment == null) {
						continue;
					}
					String path = ConfigIni.getIniStrValue("ATTACHMENT_DIR", "path",
							"C:\\file\\")
							+ coreAttachment.getCratmDir()
							+ "/"
							+ coreAttachment.getCratmFileName();

					FileUtil.deleteFile(path); // 删除缩略图
				}
			}

			list.add(uuids[i]);
		}
		if (list.size() == 0) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "请选择批量删除对象！"), response);
			return;
		}
		coreTaobaoPicService.deleteBatchByIds(list);

		writeAjaxJSONResponse(ResultMessageBuilder.build(true, 1, "批量删除成功!"),response);
		logger.info("[CoreTaobaoPicController]:end deleteBatchCoreTaobaoPic");

	}

	/**
	* 获取单个
	*
	* @param crtpcUuid 标识UUID
	* @return
	*/
	@RequestMapping(value="/views", method=RequestMethod.POST)
	public void viewsCoreTaobaoPic (String crtpcUuid, HttpServletResponse response) {
		logger.info("[CoreTaobaoPicController]:begin viewsCoreTaobaoPic");
		if (StringUtil.isEmpty(crtpcUuid)) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "[标识UUID]不能为空!"), response);
			return;
		}
		CoreTaobaoPic coreTaobaoPic = new CoreTaobaoPic();
		coreTaobaoPic.setCrtpcUuid(crtpcUuid);

		coreTaobaoPic = coreTaobaoPicService.getCoreTaobaoPic(coreTaobaoPic);

		CoreTaobaoPicVO coreTaobaoPicVO = new CoreTaobaoPicVO();
		coreTaobaoPicVO.convertPOToVO(coreTaobaoPic);
		
		String[] attachments = coreTaobaoPic.getCrtpcFile().split("\\|");
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < attachments.length; i++) {
			list.add(attachments[i]);
		}
		coreTaobaoPicVO.setCrtpcFileList(list);
				writeAjaxJSONResponse(ResultMessageBuilder.build(true, 1, "获取单个信息成功", coreTaobaoPicVO), response);
		logger.info("[CoreTaobaoPicController]:end viewsCoreTaobaoPic");

	}

	/**
	* 获取列表<List>
	* 
	* @return
	*/
	@RequestMapping(value="/find/all", method=RequestMethod.POST)
	public void findCoreTaobaoPicList (HttpServletResponse response) {
		logger.info("[CoreTaobaoPicController]:begin findCoreTaobaoPicList");
		List<CoreTaobaoPic> lists = coreTaobaoPicService.findCoreTaobaoPicList();
		List<CoreTaobaoPicVO> vos = new ArrayList<CoreTaobaoPicVO>();
		CoreTaobaoPicVO vo;
		for (CoreTaobaoPic coreTaobaoPic : lists) {
			vo = new CoreTaobaoPicVO();
			vo.convertPOToVO(coreTaobaoPic);
			vos.add(vo);
		}
		writeAjaxJSONResponse(ResultMessageBuilder.build(true, 1, "list列表获取成功!", vos),response);
		logger.info("[CoreTaobaoPicController]:end findCoreTaobaoPicList");

	}

	/**
	* 获取列表<Page>
	* 
	* @param crtpcAccount 淘宝账号
	* @param pageNum 页码
	* @param pageSize 页数
	* @return
	*/
	@RequestMapping(value="/find/by/cnd", method=RequestMethod.POST)
	public void findCoreTaobaoPicPage (String crtpcAccount, Integer pageNum, Integer pageSize, HttpServletResponse response) {
		logger.info("[CoreTaobaoPicController]:begin findCoreTaobaoPicPage");
		if (pageNum == null || pageNum == 0) {
			pageNum = 1;
		}
		if (pageSize == null || pageSize == 0) {
			pageSize = 10;
		}
		Page<CoreTaobaoPic> page = coreTaobaoPicService.findCoreTaobaoPicPage(crtpcAccount, pageNum, pageSize);
		Page<CoreTaobaoPicVO> pageVO = new Page<CoreTaobaoPicVO>(page.getPageNumber(), page.getPageSize(), page.getTotalCount());
		List<CoreTaobaoPicVO> vos = new ArrayList<CoreTaobaoPicVO>();
		CoreTaobaoPicVO vo;
		for (CoreTaobaoPic coreTaobaoPic : page.getResult()) {
			vo = new CoreTaobaoPicVO();
			vo.convertPOToVO(coreTaobaoPic);
			vos.add(vo);
		}
		pageVO.setResult(vos);
		writeAjaxJSONResponse(ResultMessageBuilder.build(true, 1, "page列表获取成功!", pageVO),response);
		logger.info("[CoreTaobaoPicController]:end findCoreTaobaoPicPage");

	}
	
	/**
	 * 获取一个文件名的后缀名（最后一个点后面的字符串）,带上点
	 * 
	 * @param fileName
	 * @return
	 */
	public String getAfterLastPoint(String fileName) {
		int last = fileName.lastIndexOf(".");
		if (last <= 0) {
			return "";
		}
		return fileName.substring(last, fileName.length());
	}
	
	/**
	 * 去除一个文件的后缀名（去除最后一个点后面的字符串）,获取文件名
	 * 
	 * @param fileName
	 * @return
	 */
	public String delAfterLastPoint(String fileName) {
		int last = fileName.lastIndexOf(".");
		if (last <= 0) {
			return "";
		}
		return fileName.substring(0, last);
	}

}